<?php
function category_format($category_list)
{
    $return = [];
    $top_categories = [];
    foreach( $category_list as $item )
    {
        if( $item['pid'] == 0 )
        {
            $top_categories[] = $item;
        }
    }
    foreach( $top_categories as $item )
    {
        $return[] = $item;
        foreach( $category_list as $category )
        {
            if( $item['id'] == $category['pid'] )
            {
                $return[] = $category;
            }
        }
    }
    return $return;
}

function getCategoryNameById($category_id)
{
//    $category = model('Category')->getById($category_id);
//    $category_name = $category['name'];
//    $up_category_name = model('Category')->getFieldById($category['pid'], 'name');
//    return $up_category_name . " - " . $category_name;

    $category = model('Category')->getById($category_id);
    $category_name = $category['name'];
    return $category_name;
}

function getDocNameById($doc_id)
{
    $name = model('Doc')->getFieldById($doc_id,'name');

    return $name ? $name : '-';
}